//
//  RadioDetailsHeaderView.m
//  aMoment
//
//  Created by dllo on 15/10/2.
//  Copyright © 2015年 LuckyHan. All rights reserved.
//

#import "RadioDetailsHeaderView.h"
#import "AllHeaderFiles.h"

@implementation RadioDetailsHeaderView

- (void)dealloc
{
    [_coverImageView release];
    [_userImageView release];
    [_usernameLabel release];
    [_listenNumField release];
    [_descLabel release];
    [_radioInfoDic release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createViews];
    }
    return self;
}

- (void)createViews
{
    _coverImageView = [[UIImageView alloc] init];
    _coverImageView.contentMode = UIViewContentModeScaleAspectFill;
    _coverImageView.clipsToBounds = YES;
    [self addSubview:_coverImageView];
    [_coverImageView release];
    
    _userImageView = [[UIImageView alloc] init];
    _userImageView.contentMode = UIViewContentModeScaleAspectFill;
    _userImageView.clipsToBounds = YES;
    [self addSubview:_userImageView];
    [_userImageView release];
    
    _usernameLabel = [[UILabel alloc] init];
    _usernameLabel.font = [UIFont systemFontOfSize:FONTSIZE_MIDDLE];
    [self addSubview:_usernameLabel];
    [_usernameLabel release];
    
    _listenNumField = [[UITextField alloc] init];
    _listenNumField.font = [UIFont systemFontOfSize:FONTSIZE_SMALL];
    _listenNumField.textColor = FONTCOLOR_GRAY;
    _listenNumField.enabled = NO;
    _listenNumField.leftViewMode = UITextFieldViewModeAlways;
    [self addSubview:_listenNumField];
    [_listenNumField release];
    
    _descLabel = [[UILabel alloc] init];
    _descLabel.numberOfLines = 0;
    [self addSubview:_descLabel];
    [_descLabel release];
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    _coverImageView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 170 * FIT_HEIGHT);
    
    _userImageView.frame = CGRectMake(20 * FIT_WIDTH, _coverImageView.Y + _coverImageView.Height + 15 * FIT_HEIGHT, IMAGE_32, IMAGE_32);
    _userImageView.layer.cornerRadius = _userImageView.Width / 2;//用户头像半径
    
    _usernameLabel.frame = CGRectMake(_userImageView.X + _userImageView.Width + 5 * FIT_WIDTH, _userImageView.Y + 6 * FIT_WIDTH, 195 * FIT_WIDTH, 20 * FIT_HEIGHT);
    _listenNumField.frame = CGRectMake(_usernameLabel.X + _usernameLabel.Width + 10 * FIT_WIDTH, _usernameLabel.Y, SCREEN_WIDTH - _usernameLabel.X - _usernameLabel.Width - 30 * FIT_WIDTH, _usernameLabel.Height);
    _descLabel.frame = CGRectMake(_userImageView.X, _userImageView.Y + _userImageView.Height + 10 * FIT_HEIGHT, SCREEN_WIDTH - 40 * FIT_WIDTH, 60 * FIT_HEIGHT);
}

- (void)setRadioInfoDic:(NSDictionary *)radioInfoDic
{
    if (_radioInfoDic != radioInfoDic) {
        [_radioInfoDic release];
        _radioInfoDic = [radioInfoDic retain];
    }
//    [_coverImageView setImageWithURL:[NSURL URLWithString:[_radioInfoDic objectForKey:@"coverimg"]]];
    [_coverImageView setImageWithURL:[NSURL URLWithString:[_radioInfoDic objectForKey:@"coverimg"]] placeholderImage:[UIImage imageNamed:@"placeholder-image"]];
//    [_userImageView setImageWithURL:[NSURL URLWithString:[[_radioInfoDic objectForKey:@"userinfo"] objectForKey:@"icon"]]];
    [_userImageView setImageWithURL:[NSURL URLWithString:[[_radioInfoDic objectForKey:@"userinfo"] objectForKey:@"icon"]] placeholderImage:[UIImage imageNamed:@"iconfont-head@2x"]];
    
    _usernameLabel.text = [[_radioInfoDic objectForKey:@"userinfo"] objectForKey:@"uname"];
    _listenNumField.text = [NSString stringWithFormat:@"%@", [_radioInfoDic objectForKey:@"musicvisitnum"]];
    _descLabel.text = [_radioInfoDic objectForKey:@"desc"];
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
